<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>File Upload</title>
    </head>
    <body>
        <form id="uploadForm" enctype="multipart/form-data">
            <input type="file" name="file" id="fileInput">
            <!-- <input type="submit" value="上传"> -->
            <button type="button" onclick="uploadFile()">Upload</button>
        </form>
        <script>
        var btn1 = document.createElement("button");
        btn1.innerHTML = "test";
        btn1.onclick = function() {
            alert("test");
        };
        document.body.appendChild(btn1);

        function uploadFile() {
            var fileInput = document.getElementById('fileInput');
            var file = fileInput.files[0];
            var formData = new FormData();
            formData.append('file', file);
            
            var xhr = new XMLHttpRequest();
            xhr.open('POST', 'http://47.96.22.83:8180/download/head/head01', true);
            xhr.onload = function () {
                document.writeln("<br>do onload 1");
                if (xhr.status === 200) {
                    alert('upload ok');
                } else {
                    alert('upload failed');
                }
            };
            xhr.send(formData);
            document.writeln("<br>send file:", file.name);
        }
    </script>
    </body>
</html>
